var app = getApp();

Page({
  data: {
    orderInfo: "",
    proId: "", //产品id
    listName: "",
    categoryName: "",
    listStaus: "", //显示不同的内容
    peopleList: "",
    peopleVal: "1",
    peoplePickerShow: false,
    yearList: [
      [1, 2, 3, 4, 5, 6]
    ],
    yearVal: "1",
    yearPickerShow: false,
    imgUrl: app.globalData.imgUrl,
    apiUrl: "",
    intime: "",
    outtime: "",
    date: '',
    datePickerValue: ['', '', ''],
    datePickerIsShow: false,
    systemInfo: {},
    padBtm: "25",
    topid: 0
  },
  onLoad: function(e) {
    var that = this;
    if (e.topid) {
      var topid = e.topid;
      that.setData({
        topid: topid
      })
      console.log("topidd", topid)
    }

    wx.getSystemInfo({
      success: function(res) {
        if (res.model == "iPhone X") {
          that.setData({
            padBtm: "50",
          })
        }
      }
    });
    var newDate = new Date();
    var nowDate = newDate.getFullYear() + '-' + (newDate.getMonth() + 1) + '-' + newDate.getDate();
    if (e.name == 'hotel') {
      var currentName = "价格明细";
      that.setData({
        apiUrl: app.globalData.apiHost + "/api/index/house"
      })
    } else if (e.name == 'serve') {
      var currentName = "确认订单";
      that.setData({
        apiUrl: app.globalData.apiHost + "/api/index/goodsDetails"
      })
    }
    if (e.category) {
      that.setData({
        categoryName: e.category
      })
    }
    that.setData({
      navH: app.globalData.navHeight,
      listName: currentName,
      listStaus: e.name,
      proId: e.id,
      date: nowDate,
      // topid: topid
    })
    that.getProDet();
  },
  onShow: function() {
    let getDate = wx.getStorageSync("ROOM_SOURCE_DATE");
    this.setData({
      intime: getDate.checkInDate,
      outtime: getDate.checkOutDate
    })
  },
  getProDet: function() {
    var that = this;
    wx.request({
      url: that.data.apiUrl,
      data: {
        id: that.data.proId
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: "POST",
      dataType: "json",
      success: function(res) {
        if (res.statusCode === 200) {
          var orderData = res.data.data;
          console.log("orderData:" + JSON.stringify(orderData));
          var maxNum = res.data.data.maximum;
          var numArr01 = [];
          var numArr02 = [];
          for (var i = 1; i <= maxNum; i++) {
            numArr01[i - 1] = i;
          }
          numArr02.push(numArr01);
          that.setData({
            orderInfo: orderData,
            peopleList: numArr02
          })
        }
      },

    });
  },
  navBack: function() {
    wx.navigateBack({
      delta: 1
    })
  },
  peoplePicker: function() {
    this.setData({
      peoplePickerShow: true
    })
  },
  sureCallBack_people(e) {
    var that = this;
    that.setData({
      peoplePickerShow: false,
      peopleVal: e.detail.choosedData[0],
    })
  },
  cancleCallBack_people() {
    this.setData({
      peoplePickerShow: false,
    })
  },
  yearPicker: function() {
    this.setData({
      yearPickerShow: true
    })
  },
  sureCallBack_year(e) {
    var that = this;
    that.setData({
      yearPickerShow: false,
      yearVal: e.detail.choosedData[0],
    })
  },
  cancleCallBack_year() {
    this.setData({
      yearPickerShow: false,
    })
  },
  showDatePicker: function(e) {
    this.setData({
      datePickerIsShow: true,
    });
  },
  datePickerOnSureClick: function(e) {
    this.setData({
      date: `${e.detail.value[0]}-${e.detail.value[1]}-${e.detail.value[2]}`,
      datePickerValue: e.detail.value,
      datePickerIsShow: false,
    });
  },
  datePickerOnCancelClick: function(event) {
    this.setData({
      datePickerIsShow: false,
    });
  },
})